<template>
  <div>
<h1 align="center">添加借款</h1>
<table class="table table-bordered">
  <tr align="center">
    <td>借款项目名称：</td>
    <td><input type="text" v-model="state.Name"></td>
  </tr>
  <tr align="center">
    <td>借款总金额：</td>
    <td><input type="text" v-model="state.Money"></td>
  </tr>
  <tr align="center">
    <td>利息：</td>
    <td>
      <select v-model="state.Iid">
        <option value="0">请选择</option>
        <option :value="item.Iid" v-for="item in list">{{ item.LiXi*100}}%</option>
      </select>
    </td>
  </tr>
  <tr align="center">
    <td></td>
    <td><input type="button" value="添加借款" @click="add"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs,onMounted} from 'vue'
import axios from 'axios'
import {useRoute,useRouter} from 'vue-router'
const route=useRoute()
const router=useRouter()

let data:any=reactive({
  list:[],
  state:{
    Name:'',
    Money:'',
    Iid:'0'
  }
})

let {list,state}=toRefs(data)

onMounted(()=>{
  getlist()
})

const getlist=()=>{
  axios({
    url:'/api/Default/GetInterests',
    method:'get',
  })
  .then(res=>{
    console.log(res);
    list.value=res.data.data
  })
  .catch(err=>{
    console.log(err);
  })
}

const add=()=>{
  axios({
    url:'/api/Default/PostAdd',
    method:'post',
    data:state.value
  })
  .then(res=>{
    console.log(res)
    if(res.data.data>0){
      alert('添加成功');
      router.push('/show');
    }
    else{
      alert('添加失败');
    }
  })
  .catch(err=>{
    console.log(err);
  })
}
</script>

<style scoped>

</style>